<template>
    <div class="sys-page">
        <app-title title="用户高频登录管理"  style="display:inline;"></app-title>
         <el-button type="success" @click="refresh()" round style="float:right; margin-top:10px;" icon="el-icon-refresh">刷新</el-button>
            <el-table v-loading="loading" border :data="tableData.body" :row-class-name="tableRowClassName">
                <el-table-column prop="loginFailCnt" label="高频登陆次数阈值(次/小时)" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" size="small" @click="edit">修改</el-button>
                    </template>
                </el-table-column>
            </el-table>
           
            <el-dialog :title="dialogTitle" :visible.sync="editTableShow" width='40%' :fullscreen='false'>
                <el-select v-model="selectVal" placeholder="1">
                    <el-option
                    v-for="item in 20"
                    :key="item"
                    :label="item"
                    :value="item">
                    </el-option>
                </el-select>
                <el-button @click.native.prevent="ok">确定</el-button>
                <el-button @click.native.prevent="cancel">取消</el-button>

            </el-dialog>
    </div>

</template>
<style>
  .el-table .warning-row {
    background: #F08080;
  }

  .el-table .success-row {
    background:#f0f9eb;
  }
</style>

<script>
export default {
    name:'highFrequencyLogin',
    data(){
        return {
            dialogTitle:"用户高频登录次数阈值设置(次/小时)",
            failcnt:1,
            loading: false,
            editTableShow: false,
            selectVal:1,
            tableData:{
                body:[{loginFailCnt: ''}],
                head:[],
                loading:true
            },
            issafe:true

       }
    },
    mounted(){
        this.query()
    },
    methods:{
        refresh(){
            this.query()
        },
        tableRowClassName({row, rowIndex}) {
          if(this.issafe === false){
            return 'warning-row';
          }else{
              return 'success-row'
          }
        },
        edit(){
            console.log("edit")
            this.selectVal = this.tableData.body[0].loginFailCnt
           this.editTableShow = true
        },
        ok(){
            this.editTableShow = false
            this.failcnt = this.selectVal

            this.HTTP.methods.apiPost("/sysconfig/b0008.shtml",{content:this.failcnt}).then(res =>
                {
                   if (res.code != 200) {
                       this.$message("设置失败")
                    } else {
                        this.tableData.body[0].loginFailCnt = this.selectVal
                       this.$message("设置成功")
                    }

                })
            this.editTableShow = false
        },
        cancel(){
            this.editTableShow = false
            this.failcnt = 1
            this.selectVal = 1

        },
        //缺少一种点进去链接，就发请求的listener
        query(){
            this.HTTP.methods.apiGet("/sysconfig/b0008.shtml", {}).then(res =>
            {
                console.log(res)
                if(res.code != 200){
                    console("highFrequencyLogin get request fail")
                    // this.tableData.body[0].loginFailCnt = ''
                }else{
                    this.tableData.body[0].loginFailCnt = res.data.content
                }
            }
            )
        }
    }
}
</script>


